package com.example.myapplication11_10;


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.PercentFormatter;


import java.util.ArrayList;
import java.util.List;


public class Main3Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        PieChart pieChart = findViewById(R.id.pic_chart);
        List<PieEntry> strings = new ArrayList<>();
        strings.add(new PieEntry(40f, "蟹肉披萨"));
        strings.add(new PieEntry(30f, "兰州拉面"));
        strings.add(new PieEntry(20f, "蟹黄堡"));
        strings.add(new PieEntry(10f, "香辣鸡腿"));
        PieDataSet dataSet = new PieDataSet(strings, "产品");

        ArrayList<Integer> colors = new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.magenta));
        colors.add(getResources().getColor(R.color.colorAccent));
        colors.add(getResources().getColor(R.color.chocolate));
        colors.add(getResources().getColor(R.color.darkSlateBlue));
        dataSet.setColors(colors);

        PieData pieData = new PieData(dataSet);
        pieData.setDrawValues(true);
        pieData.setValueFormatter(new PercentFormatter());
        pieData.setValueTextSize(12f);

        pieChart.setData(pieData);
        pieChart.invalidate();

        Description description = new Description();
        description.setText("售卖比图");
        pieChart.setDescription(description);
        pieChart.setHoleRadius(0f);
        pieChart.setTransparentCircleRadius(0f);




    }
}
